package conson.tech.manage.facade.controller.coupons;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import conson.tech.core.constant.SecurityConstants;
import conson.tech.core.response.Response;
import conson.tech.manage.coupons.entity.dto.*;
import conson.tech.manage.coupons.entity.vo.CouponsBatchCenterVo;
import conson.tech.manage.coupons.entity.vo.CouponsCenterVo;
import conson.tech.manage.coupons.service.CouponsCenterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

@Slf4j
@Api(value = "领券中心配置", tags = "领券中心配置模块")
@RestController
@RequestMapping((SecurityConstants.MANAGERAPI + "/coupons-center"))
public class CouponsCenterController extends BaseController {


    @Autowired
    private CouponsCenterService couponsCenterService;


    @ApiOperation(value = "领券中心配置查询")
    @ApiImplicitParam(name = "couponsType", value = "领券类型1 限时抢  2领券", required = true, dataType = "Integer")
    @GetMapping("/coupons/center/query-list/{couponsType}")
    public Response<List<CouponsCenterVo>> queryList(@ApiParam("领券类型") @PathVariable("couponsType") Integer couponsType) {

        return Response.success(this.couponsCenterService.queryList(couponsType));
    }

    @ApiOperation(value = "查询优惠券批次列表")
    @ApiImplicitParam(name = "dto", value = "查询优惠券批次列表", required = true, dataType = "CouponsCenterDto")
    @PostMapping("/coupons/center/query-coupons-list/{pageSize}/{pageIndex}")
    public Response<Page<CouponsBatchCenterVo>> queryCouponsList(@ApiParam("每页条数") @PathVariable("pageSize") Integer pageSize,
                                                                 @ApiParam("页码") @PathVariable("pageIndex") Integer pageIndex,
                                                                 @Valid @ApiParam(value = "查询参数") @RequestBody CouponsCenterDto dto) {

        return Response.success(this.couponsCenterService.queryCouponsList(pageSize, pageIndex, dto));
    }

    @ApiOperation(value = "新增限时抢优惠券配置")
    @ApiImplicitParam(name = "dto", value = "新增限时抢入参", required = true, dataType = "CouponsCenterAddTimeDto")
    @PostMapping("/coupons/center/add-time")
    public Response addTimeCouponsCenter(HttpServletRequest request, @ApiParam(value = "查询参数") @Valid @RequestBody CouponsCenterAddTimeDto dto) {


//        Long userId = this.getCurrentUserId(request);
        Long userId = 123456789L;
        String currentUsername = "广电测试";
        return this.couponsCenterService.addTimeCouponsCenter(dto, userId, currentUsername);

    }

    @ApiOperation(value = "删除限时抢优惠券")
    @ApiImplicitParam(name = "id", value = "删除限时抢优惠券", required = true, dataType = "Long")
    @GetMapping("/coupons/center/del-time/{id}")
    public Response delTimeCouponsCenter(@ApiParam("领券类型") @PathVariable("id") Long id) {

        Long userId = 123456789L;
        String currentUsername = "广电测试";
        return this.couponsCenterService.delTimeCouponsCenter(userId, currentUsername, id);
    }


    @ApiOperation(value = "修改限时抢优惠券")
    @ApiImplicitParam(name = "dto", value = "修改限时抢优惠券", required = true, dataType = "CouponsCenterEditTimeDto")
    @PostMapping("/coupons/center/edit-time/{id}")
    public Response editTimeCouponsCenter(HttpServletRequest request, @ApiParam("优惠券活动id") @PathVariable("id") Long id, @Valid @RequestBody CouponsCenterEditTimeDto dto) {

//        Long userId = this.getCurrentUserId(request);
        Long userId = 123456789L;
        String currentUsername = "广电测试";
        return this.couponsCenterService.editTimeCouponsCenter(id, dto, userId, currentUsername);
    }

    @ApiOperation(value = "新增领券接口")
    @ApiImplicitParam(name = "dto", value = "新增领券接口入参", required = true, dataType = "CouponsCenterAddReceiveDto")
    @PostMapping("/couopons/center/add-receive")
    public Response addReceiveCouponsCenter(HttpServletRequest request, @ApiParam(value = "查询参数") @Valid @RequestBody CouponsCenterAddReceiveDto dto) {

//        Long userId = this.getCurrentUserId(request);
        Long userId = 123456789L;
        String currentUsername = "广电测试";
        return this.couponsCenterService.addReveiceCouponsCenter(userId, currentUsername, dto);
    }

    @ApiOperation(value = "删除领券接口")
    @ApiImplicitParam(name = "id", value = "删除一条领券活动", required = true, dataType = "id")
    @GetMapping("/coupons/center/del-receive/{id}")
    public Response delReceiveCouponsCenter(@ApiParam("优惠券活动id") @PathVariable("id") Long id) {

        Long userId = 123456789L;
        String currentUsername = "广电测试";
        return this.couponsCenterService.delReceiveCouponsCenter(userId, currentUsername, id);
    }

    @ApiOperation(value = "修改领用券接口")
    @ApiImplicitParam(name = "dto", value = "修改某条领券活动", required = true, dataType = "CouponsCenterEditReceiveDto")
    @PostMapping("/coupons/center/edit-receive/{id}")
    public Response editReceiveCouponsCenter(HttpServletRequest request, @ApiParam("优惠券活动id") @PathVariable("id") Long id, @Valid @RequestBody CouponsCenterEditReceiveDto dto) {

//        Long userId = this.getCurrentUserId(request);
        Long userId = 123456789L;
        String currentUsername = "广电测试";
        return this.couponsCenterService.editReceiveCouponsCenter(userId, currentUsername, id, dto);
    }


}
